/*  
 *  Copyright 2006 Paul Jack.
 *
 *  This file is part of the Dex compiler suite. 
 *  
 *  Dex is free software; you can redistribute it and/or modify it
 *  under the terms of the GNU General Public License as published by the
 *  Free Software Foundation; either version 2 of the License, or (at your
 *  option) any later version.
 *  
 *  Dex is distributed in the hope that it will be useful, but
 *  WITHOUT ANY WARRANTY; without even the implied warranty of
 *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General
 *  Public License for more details.
 *  
 *  You should have received a copy of the GNU General Public License along
 *  with this program; if not, write to the Free Software Foundation, Inc.,
 *  51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA
 */
package dex.compiler.model.statement;


import dex.compiler.model.base.ParseNode;
import dex.compiler.model.base.Place;
import dex.compiler.model.type.TypeNode;


/**
 * A catch portion of a try/catch block.
 */
public class CatchBlock extends ParseNode {


	/**
	 * The type of the exception to catch.
	 */
	TypeNode type;
	
	
	/**
	 * An identifier for the caught exception.
	 */
	String id;
	
	
	/**
	 * The block to execute when the exception is caught.
	 */
	Block block;


	/**
	 * Constructs a new catch block.
	 * 
	 * @param place  the place where the catch block originated
	 * @param type   the type of exception to be caught
	 * @param id     an identifier for the caught exception
	 * @param block  the block to execute when the exception is caught
	 */
	public CatchBlock(Place place, TypeNode type, String id, Block block) {
		super(place);
		this.type = type;
		this.id = id;
		this.block = block;
	}
	
	
	@Override
	public String toString() {
		StringBuilder result = new StringBuilder("catch ");
		result.append(type).append(' ').append(id).append("\n");
		result.append(block);
		return result.toString();
	}


	/**
	 * Returns the block to execute when the exception is caught.
	 * 
	 * @return  the block to execute when the exception is caught
	 */
	public Block getBlock() {
		return block;
	}


	/**
	 * Returns the identifier of the caught exception.
	 * 
	 * @return  the identifier of the caught exception
	 */
	public String getIdentifier() {
		return id;
	}


	/**
	 * Returns the type of the exception to catch.
	 *
	 * @return  the type of the exception to catch
	 */
	public TypeNode getType() {
		return type;
	}


}
